package com.hai.security;

import java.io.IOException;

import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;

import org.apache.wss4j.common.ext.WSPasswordCallback;

public class MySecurity implements CallbackHandler{

	@Override
	public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
		WSPasswordCallback wsp=(WSPasswordCallback) callbacks[0];
		String user = wsp.getIdentifier();
		String psw = null;
		if("hai".equals(user)) {
			psw= "123";
		}
		wsp.setPassword(psw);				
	}

	
	/*请求的xml示例
	  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://server.hai.com/">
        <soapenv:Header>
          <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1">
            <wsse:UsernameToken>
              <wsse:Username>hai</wsse:Username>
              <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">123</wsse:Password>
            </wsse:UsernameToken>
          </wsse:Security>
        </soapenv:Header>

		   <soapenv:Body>
		      <ser:speak>
		         
		      <arg0>青浦</arg0></ser:speak>
		   </soapenv:Body>
		</soapenv:Envelope>
	 * */
}
